package com.mls.fivedistrict.server.impl;

import com.mls.fivedistrict.pojo.RoleMenu;
import com.mls.fivedistrict.dao.RoleMenuMapper;
import com.mls.fivedistrict.server.RoleMenuService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 角色菜单列表 服务实现类
 * </p>
 *
 * @author Five Team
 * @since 2018-06-14
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {
    @Autowired
    RoleMenuMapper roleMenuMapper;
    @Transactional
    @Override
    public boolean updateBatch(List<RoleMenu> list,Long roleId) {
        boolean delete=false;
        boolean insert=false;
        List<RoleMenu> before = roleMenuMapper.getListByRoleId(roleId);
        //之前不为空，删除掉
        if(null!=before&&before.size()>0){
            delete= roleMenuMapper.deleteAllByRoleId(roleId);
        }
        if(null!=list&&list.size()>0){
            //直接新增
            insert=roleMenuMapper.insertBatch(list);
        }
        if(insert||delete){
            return  true;
        }
        return false;
    }
}
